package net.zretc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import net.zretc.entity.Cart;
import net.zretc.mapper.CartMapper;
import net.zretc.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CartServiceImpl implements CartService {

    @Autowired
    private CartMapper cartMapper;

    @Override
    public List<Cart> findAll() {
        return cartMapper.selectList(null);
    }

    @Override
    public List<Cart> findByUserId(Integer userId) {
        QueryWrapper<Cart> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        return cartMapper.selectList(queryWrapper);
    }

    @Override
    public int insert(Cart cart) {
        return cartMapper.insert(cart);
    }

    @Override
    public int update(Cart cart) {
        return cartMapper.updateById(cart);
    }

    @Override
    public int delete(Integer cartId) {
        return cartMapper.deleteById(cartId);
    }
}